package com.example.sixtrainingdemo.view;

import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.sixtrainingdemo.R;
import com.example.sixtrainingdemo.adapter.TalkListAdapter;
import com.example.sixtrainingdemo.base.BaseFragment;
import com.example.sixtrainingdemo.contract.TalkContract;
import com.example.sixtrainingdemo.entity.Talk;
import com.example.sixtrainingdemo.presenter.TalkPresenter;

import java.util.ArrayList;
import java.util.List;

public class TalkFragment extends BaseFragment implements TalkContract.ITalkView, View.OnClickListener  {

   private RecyclerView mTalkRecyclerView;
   private TalkListAdapter mRecyclerAdapter;
   private TalkContract.ITalkPresenter mTalkPresenter;
   private List<Talk> mTalkList;

   @Override
   protected int getLayoutId() {
      return R.layout.fragment_talk;
   }

   @Override
   protected void initView() {
      mTalkPresenter = new TalkPresenter(this, getContext());
      mTalkList = new ArrayList<>();
      mTalkRecyclerView = mView.findViewById(R.id.rv_talk);
      StaggeredGridLayoutManager staggeredGridLayoutManager =
              new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
      mTalkRecyclerView.setLayoutManager(staggeredGridLayoutManager);
      mRecyclerAdapter = new TalkListAdapter(mTalkList);
      mTalkRecyclerView.setAdapter(mRecyclerAdapter);
      mTalkPresenter.getTalkList();
   }

   @Override
   protected void initListener() {

   }

   @Override
   public void onResume() {
      super.onResume();
      mTalkPresenter.getTalkList();
   }

   @Override
   public void showTalkList(List<Talk> talkList) {
      mTalkList = talkList;
      Log.d("", "showRoundList " + mTalkList.size());
      mRecyclerAdapter.updateData(mTalkList);
   }

   @Override
   public void onClick(View v) {
//      int id = v.getId();
//      if (id == R.id.gosale) {
//         Intent intent = new Intent(mContext, Main1Activity.class);
//         startActivity(intent);
//      }
   }

}
